<?php
$q=$_GET["q"];
$hint='';
include_once ("../Login/databaseconnection.php");
require_once ("../Login/config.php");
$name=explode(",",$q);
$nam=$name[0];
$tn=count($name);
if(count($name)>4)
{
for($i=1;$i<$tn-2;$i++)
{
if(empty($adr))
{
$adr=$name[$i];
}
else
{
$adr=$adr.",".$name[$i];
}
}
}
else if(count($name)==4)
{
$adr=$name[1];
}
$Access_Type=$name[$tn-2];
$NIC_Number=$name[$tn-1];
$Exc_que="SELECT * FROM school Where Name='$nam' AND Address='$adr'";
$result = mysql_query("SELECT * FROM school Where Name='$nam' AND Address='$adr'");
if($row = mysql_fetch_array($result))
{
$Census_Number=$row['Census_Number'];
$id=$row['School_Id'];
$hint="<font color='black'>The Censusnumber of this School is :".$Census_Number."<br/>";
$colu="";
	if($Access_Type=="Teacher in Charge"||$Access_Type=="Teacher")
{
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
   $get_Cen=mysql_query("SELECT * FROM school WHERE School_Id='".$Own_School_Id."'");
   if($rowcen=mysql_fetch_array($get_Cen))
   {
    $Own_Census_Number=$rowcen['Census_Number'];
    if($Census_Number==$Own_Census_Number)
	{
	$colu="";
	$Exc_que="SELECT * FROM school WHERE Census_Number='$Census_Number'";
	$result=mysql_query("SELECT * FROM school WHERE Census_Number='$Census_Number'");
	$sql=mysql_query("SHOW COLUMNS FROM school");
	while($rowc=mysql_fetch_row($sql))
  {
  if(empty($colu))
  {
  $colu=$rowc[0];
  }
  else
  {
   $colu=$colu.",".$rowc[0];
  }
  }if(mysql_num_rows($sql)>11||mysql_num_rows($result)>11)
{
$hint=$hint.'<div style="width:500px; height:600px; overflow-Y:scroll; ">';
}
      $hint=$hint.'<table border="0" class="tablefontv">';
	 $columns=explode(",",$colu);
        if($row=mysql_fetch_array($result))
  {
   for($cv=0;$cv<mysql_num_rows($sql);$cv++)
	{
	 $col_name=$columns[$cv];
	  $co_name= str_replace("_"," ",$col_name);
	     $hint=$hint."<tr><td bgcolor='#0054A8' width='500'>".$co_name." :</td><td bgcolor='#6AB5FF' width='250' height='40'>";
		$col_val=$row[$col_name];
	 $hint=$hint."<input type='text' name='$col_name' value='$col_val' readonly='readonly' size='30'></td></tr>";
	}
	 $hint=$hint."<tr><td bgcolor='#0054A8'>Total number of teachers :";
	 $hint=$hint.'</td>';
	$que=mysql_query("SELECT * FROM teacher WHERE School_Id='$School_Id'");
$tea=mysql_num_rows($que);
     $hint=$hint.'<td bgcolor="#6AB5FF" height="40">';
	 $hint=$hint."<input type='text' name='T_No_Teachers' value='$tea' readonly='readonly' size='30'>";
	 $hint=$hint.'</td></tr><tr><td width="186" bgcolor="#0054A8">Total number of computer labs :</td>';
	$quer=mysql_query("SELECT * FROM lab WHERE School_Id='$School_Id'");
	$lab=mysql_num_rows($quer);
     $hint=$hint.'<td bgcolor="#6AB5FF" height="40">';
	 $hint=$hint."<input type='text' name='T_No_Labs' value='$lab' readonly='readonly' size='25'>";
	 $hint=$hint.'</td></tr></table>';
if(mysql_num_rows($sql)>11||mysql_num_rows($result)>11)
{
$hint=$hint.'</div>';
}
	}
	 }
	  }
   }
   $hint=$hint.'</font>';
      }
   else if($Access_Type=="Administrator")
{
$Exc_que="SELECT * FROM school WHERE Census_Number='$Census_Number'";
 	$result=mysql_query("SELECT * FROM school WHERE Census_Number='$Census_Number'");
	   $sql=mysql_query("SHOW COLUMNS FROM school");
	   while($rowc=mysql_fetch_row($sql))
  {
  if(empty($colu))
  {
   $colu=$rowc[0];
  }
  else
  {
   $colu=$colu.",".$rowc[0];
  }
  }
if(mysql_num_rows($sql)>11||mysql_num_rows($result)>11)
{
$hint=$hint.'<div style="width:500px; height:600px; overflow-Y:scroll; ">';
}
      $hint=$hint.'<table border="0" class="tablefontv">';
	 $columns=explode(",",$colu);
        if($row=mysql_fetch_array($result))
  {
   for($cv=0;$cv<mysql_num_rows($sql);$cv++)
	{
	 $col_name=$columns[$cv];
	  $co_name= str_replace("_"," ",$col_name);
	     $hint=$hint."<tr><td bgcolor='#0054A8' width='500'>".$co_name." :</td><td bgcolor='#6AB5FF' width='250' height='25'>";
		$col_val=$row[$col_name];
	 $hint=$hint."<input type='text' name='$col_name' value='$col_val' readonly='readonly' size='30'></td></tr>";
	}
	 $hint=$hint."<tr><td bgcolor='#0054A8'>Total number of teachers :";
	 $hint=$hint.'</td>';
	$que=mysql_query("SELECT * FROM teacher WHERE School_Id='$School_Id'");
$tea=mysql_num_rows($que);
     $hint=$hint.'<td bgcolor="#6AB5FF" height="40">';
	 $hint=$hint."<input type='text' name='T_No_Teachers' value='$tea' readonly='readonly' size='30'>";
	 $hint=$hint.'</td></tr><tr><td width="186" bgcolor="#0054A8">Total number of computer labs :</td>';
	$quer=mysql_query("SELECT * FROM lab WHERE School_Id='$School_Id'");
	$lab=mysql_num_rows($quer);
     $hint=$hint.'<td bgcolor="#6AB5FF" height="40">';
	 $hint=$hint."<input type='text' name='T_No_Labs' value='$lab' readonly='readonly' size='30'>";
	 $hint=$hint.'</td></tr></table>';
if(mysql_num_rows($sql)>11||mysql_num_rows($result)>11)
{
$hint=$hint.'</div>';
}
	}
	$hint=$hint.'</font>';
}
else
{
 $hint=$hint.'<font class="err"><img src="../images/alert.jpg" width="12" height="12"/> There are no results for your search!</font>';
}
 if($result)
{
$Exc_quer=str_replace("'","@",$Exc_que);
$hint=$hint."<form action='../exportreport.php' method='post'><input type='submit' name='ToExcel' class='print' value=''/><input type='hidden' value='$Exc_quer' name='query'/><input type='hidden' value='school' name='Exc_table_name'/></form>";
}
}
if($hint==""||$hint=="<font color='black'>The Censusnumber of this School is :".$Census_Number."<br/></font>")
{
echo $hint."<br/>";
$response='<font class="err"><img src="../images/alert.jpg" width="12" height="12"/> There are no more results for you!</font>';
}
else
{
$response=$hint;
}
echo $response;
?>